import Vue from 'vue'
import request from './request'
function getInterface(url, params = {}, header = {}) {
    return request({
        method: 'get',
        url: process.env.NODE_ENV === 'development' ? url : '/api' + url,
        params,
        ...header
    })
}

function postInterface(url, data = {}, headers = {}) {
    return request({
        method: 'post',
        url: process.env.NODE_ENV === 'development' ? url : '/api' + url,
        data,
        ...headers
    })
}

function putInterface(url, data = {}) {
    return request({
        method: 'put',
        url: process.env.NODE_ENV === 'development' ? url : '/api' + url,
        data
    })
}

function deleteInterface(url, data = {}) {
    return request({
        method: 'delete',
        url: process.env.NODE_ENV === 'development' ? url : '/api' + url,
        data
    })
}

function Interface() {
    // 将组件注册到 vue 的 原型链里去
    Vue.prototype.$get = getInterface
    Vue.prototype.$post = postInterface
    Vue.prototype.$put = putInterface
    Vue.prototype.$delete = deleteInterface
}
export default Interface
